DEF_PROJECT=../../..
include $(DEF_PROJECT)/scripts/main.mk
name=coreutils
version=8.19
prefix=/usr
destdir=$(DIR_SYSROOT)
extdeps=eglibc-tools gcc-tools binutils-tools linux-header-tools

DL_SERV=http
DL_HOST=ftp.gnu.org
DL_PATH=gnu/$(name)
DL_SUFFIX=tar.xz

cflags+=--host=$(CC_TARGET)
cflags+=--build=$(CC_HOST)
cflags+=--cache-file=$(DEF_CACHE)
cflags+=--enable-no-install-program=kill,uptime
cflags+=--enable-install-program=hostname

pre-build:
	echo fu_cv_sys_stat_statfs2_bsize=yes >$(source)/$(DEF_CACHE)
	echo gl_cv_func_rename_trailing_slash_bug=no >>$(source)/$(DEF_CACHE)
	echo gl_cv_func_mbrtowc_incomplete_state=yes >>$(source)/$(DEF_CACHE)
	echo gl_cv_func_mbrtowc_nul_retval=yes >>$(source)/$(DEF_CACHE)
	echo gl_cv_func_mbrtowc_null_arg=yes >>$(source)/$(DEF_CACHE)
	echo gl_cv_func_mbrtowc_retval=yes >>$(source)/$(DEF_CACHE)
	echo gl_cv_func_btowc_eof=yes >>$(source)/$(DEF_CACHE)
	echo gl_cv_func_wcrtomb_retval=yes >>$(source)/$(DEF_CACHE)
	echo gl_cv_func_wctob_works=yes >>$(source)/$(DEF_CACHE)
	cd $<;$(cdefs) ./configure $(cflags)

post-build:
	$(MAKE) -C $(if $(build),$(build),$(source)) $(iflags)
	mv $(destdir)/usr/bin/{cat,chgrp,chmod,chown,cp,date} $(destdir)/bin
	mv $(destdir)/usr/bin/{dd,df,echo,false,hostname,ln,ls,mkdir} $(destdir)/bin
	mv $(destdir)/usr/bin/{mv,pwd,rm,rmdir,stty,true,uname} $(destdir)/bin
	mv $(destdir)/usr/bin/chroot $(destdir)/usr/sbin
	mv $(destdir)/usr/bin/{[,basename,head,install,nice} $(destdir)/bin
	mv $(destdir)/usr/bin/{readlink,sleep,sync,test,touch} $(destdir)/bin
	ln -sf ../../bin/install $(destdir)/usr/bin
